package Game.Core;

import Game.Entity.ConfigEntity;
import Game.Entity.MatchEntity;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;

import org.json.JSONException;
import org.json.JSONObject;
import org.json.JSONArray;

/**
 * Created by michaelfrandin on 15/05/14.
 */
public class Match {
    /**
     * Configuração da partatida
     */
    private ConfigEntity config;

    /**
     * Pasta para partidas prestes a começar
     */
    private String dirPlay;

    /**
     *
     */
    private ArrayList<String> matchs;

    /**
     * Construtor
     */
    public Match(ArrayList<String> matchs, String dirPlay) {
        this.dirPlay = dirPlay;
        this.matchs = matchs;

        this.config = new ConfigEntity();
        this.config.setBreakTime(100)
                .setRate(1.5)
                .setTime(600)
                .setTurn(10);
    }

    public void start()
    {

        this.getMatchData(this.dirPlay + this.matchs.get(0));
        /*for (int i=0; i < this.config.getTurn(); i++) {
            for (int j=0; j < this.matchs.size(); j++) {
                this.getMatchData(this.dirPlay + this.matchs.get(i));
            }
        }*/
    }

    /**
     * Abre arquivo de partida
     * @param match String Nome do arquivo que sera aberto
     * @return
     */
    private JSONObject getMatchData(String match) {
        JSONObject jsonReturn = new JSONObject("{}");

        try {
            FileReader fileReader = new FileReader(match);
            BufferedReader reader = new BufferedReader(fileReader);

            jsonReturn = new JSONObject(reader.readLine());

        } catch (IOException e) { System.err.printf("Erro na abertura do arquivo: %s.\n", e.getMessage()); }

        return jsonReturn;
    }
}
